package com.ipzoe.web.controller.act;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ipzoe.common.utils.SecurityUtils;
import com.ipzoe.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ipzoe.common.annotation.Log;
import com.ipzoe.common.core.controller.BaseController;
import com.ipzoe.common.core.domain.AjaxResult;
import com.ipzoe.common.enums.BusinessType;
import com.ipzoe.act.domain.ActivitySignup;
import com.ipzoe.act.service.IActivitySignupService;
import com.ipzoe.common.utils.poi.ExcelUtil;
import com.ipzoe.common.core.page.TableDataInfo;

/**
 * 活动报名Controller
 * 
 * @author eric
 * @date 2020-08-20
 */
@RestController
@RequestMapping("/act/activitySignup" )
public class ActivitySignupController extends BaseController {

    @Autowired
    private IActivitySignupService iActivitySignupService;

    /**
     * 查询活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('act:activitySignup:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivitySignup activitySignup)
    {
        startPage();
        LambdaQueryWrapper<ActivitySignup> lqw = new LambdaQueryWrapper<ActivitySignup>();
        if (activitySignup.getActivityId() != null){
            lqw.eq(ActivitySignup::getActivityId ,activitySignup.getActivityId());
        }
        if(StringUtils.isNotEmpty(activitySignup.getMobile())){
            lqw.eq(ActivitySignup::getMobile, activitySignup.getMobile());
        }
        List<ActivitySignup> list = iActivitySignupService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('act:activitySignup:export')" )
    @Log(title = "活动报名" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(ActivitySignup activitySignup) {
        LambdaQueryWrapper<ActivitySignup> lqw = new LambdaQueryWrapper<ActivitySignup>(activitySignup);
        List<ActivitySignup> list = iActivitySignupService.list(lqw);
        ExcelUtil<ActivitySignup> util = new ExcelUtil<ActivitySignup>(ActivitySignup. class);
        return util.exportExcel(list, "activitySignup" );
    }

    /**
     * 获取活动报名详细信息
     */
    @PreAuthorize("@ss.hasPermi('act:activitySignup:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iActivitySignupService.getById(id));
    }

    /**
     * 签到
     */
    @PreAuthorize("@ss.hasPermi('act:activitySignup:signin')" )
    @PutMapping(value = "/signin/{id}" )
    public AjaxResult signin(@PathVariable("id" ) Long id) {
        iActivitySignupService.signin(id, SecurityUtils.getUsername());
        return AjaxResult.success(1);
    }

    /**
     * 新增活动报名
     */
    @PreAuthorize("@ss.hasPermi('act:activitySignup:add')" )
    @Log(title = "活动报名" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivitySignup activitySignup) {
        return toAjax(iActivitySignupService.save(activitySignup) ? 1 : 0);
    }

    /**
     * 修改活动报名
     */
    @PreAuthorize("@ss.hasPermi('act:activitySignup:edit')" )
    @Log(title = "活动报名" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivitySignup activitySignup) {
        return toAjax(iActivitySignupService.updateById(activitySignup) ? 1 : 0);
    }

    /**
     * 删除活动报名
     */
    @PreAuthorize("@ss.hasPermi('act:activitySignup:remove')" )
    @Log(title = "活动报名" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iActivitySignupService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
